<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <pre lang="java"><code>
public static void start() throws IOException, RuntimeException{
    throw new RuntimeException("Not able to Start");
 }

 public static void main(String args[]) {
    BufferedReader br = null;
    try {
        String line;
        br = new BufferedReader(new FileReader("\home\usr\test.java"));
        while ((line = br.readLine()) != null) {
            start();
        }
        return;
    } catch (Exception ex) {
        ex.printStackTrace();
    } catch (RuntimeException re) {
        re.printStackTrace();
    } finally {
        // 是否会输出？
        System.out.print("1");
    }
 }
</code></pre>
  <h1 data-lake-id="JtzPX" id="JtzPX"><span data-lake-id="ua5502937" id="ua5502937">典型回答</span></h1>
  <ol list="u9e2838e2">
   <li fid="u68a89748" data-lake-id="u388a43e3" id="u388a43e3"><code data-lake-id="ue345b2de" id="ue345b2de"><span data-lake-id="ud6428451" id="ud6428451">#start</span></code><span data-lake-id="uf9ec2bc8" id="uf9ec2bc8">方法不会发生IOException，所以不需要throw</span></li>
   <li fid="u68a89748" data-lake-id="u56634572" id="u56634572"><span data-lake-id="u9ac776f1" id="u9ac776f1">RuntimeExcption不需要显式的throw</span></li>
   <li fid="u68a89748" data-lake-id="uf541aac0" id="uf541aac0"><span data-lake-id="u0d9f6a14" id="u0d9f6a14">catch的时候，要先从子类开始catch，代码中catch的顺序不对</span></li>
   <li fid="u68a89748" data-lake-id="uc64d8407" id="uc64d8407"><span data-lake-id="u86744fcd" id="u86744fcd">没有关闭流</span></li>
   <li fid="u68a89748" data-lake-id="uf2cae54c" id="uf2cae54c"><span data-lake-id="ub1e5a2da" id="ub1e5a2da">return之前的finally block是会被执行的</span></li>
  </ol>
  <h1 data-lake-id="MPGFr" id="MPGFr"><span data-lake-id="u1db728f9" id="u1db728f9">知识扩展</span></h1>
  <h2 data-lake-id="phm7K" id="phm7K"><span data-lake-id="u851bf3c8" id="u851bf3c8">上述代码，如何优化</span></h2>
  <pre lang="java"><code>
public static void main(String... args) {
    try (BufferedReader br = new BufferedReader(new FileReader("\home\usr\test.java"))) {
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException e) {
        // handle exception
    }
}
</code></pre>
  <h2 data-lake-id="iLATj" id="iLATj"><span data-lake-id="uf0bd2d33" id="uf0bd2d33">try-with-resource的原理</span></h2>
  <p data-lake-id="u22d46850" id="u22d46850"><span data-lake-id="u9c935148" id="u9c935148">javac使用了语法糖进行优化</span></p>
  <pre lang="java"><code>
public static void main(String args[]) {
    BufferedReader br;
    Throwable throwable;
    br = new BufferedReader(new FileReader("\home\usr\test.java"));
    throwable = null;
    String line;
    try {
        while((line = br.readLine()) != null)
        System.out.println(line);
    } catch(Throwable throwable2) {
        throwable = throwable2;
        throw throwable2;
    }finally{
        if(br != null)
        if(throwable != null)
        try {
        	br.close();
        } catch(Throwable throwable1) {
        	throwable.addSuppressed(throwable1);
        }
    else
    	br.close();
    }
}
</code></pre>
  <h2 data-lake-id="qeOuQ" id="qeOuQ"><span data-lake-id="uff652310" id="uff652310" style="color: var(--yq-text-primary)">Java7中还对异常做了哪些优化？</span></h2>
  <ol list="u682fc7a8">
   <li fid="u0fc23b1c" data-lake-id="u7ac11eb8" id="u7ac11eb8"><span data-lake-id="u73479e74" id="u73479e74" class="lake-fontsize-11" style="color: var(--yq-text-primary)">Multi-Catch Exceptions，可以连续处理多个异常，如：</span></li>
  </ol>
  <pre lang="java"><code>
public class ExampleExceptionHandlingNew
{
   public static void main( String[] args )
   {
    try {
        URL url = new URL("http://www.yoursimpledate.server/");
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(url.openStream()));
        String line = reader.readLine();
        SimpleDateFormat format = new SimpleDateFormat("MM/DD/YY");
        Date date = format.parse(line);
    }
    catch(ParseException | IOException exception) {
        // handle our problems here.
    }
   }
}
</code></pre>
  <ol list="u682fc7a8" start="2">
   <li fid="u0fc23b1c" data-lake-id="uae2fed14" id="uae2fed14"><span data-lake-id="ude1a7e3e" id="ude1a7e3e" class="lake-fontsize-11" style="color: var(--yq-text-primary)">Rethrowing Exceptions</span></li>
   <li fid="u0fc23b1c" data-lake-id="uc26cd976" id="uc26cd976"><span data-lake-id="u4336bb44" id="u4336bb44" class="lake-fontsize-11" style="color: var(--yq-text-primary)">Suppressed Exceptions</span></li>
   <li fid="u0fc23b1c" data-lake-id="ue435dbc1" id="ue435dbc1"><a href="https://www.oracle.com/technical-resources/articles/java/java7exceptions.html" target="_blank" data-lake-id="u16d1ad73" id="u16d1ad73"><span data-lake-id="u27062867" id="u27062867" class="lake-fontsize-11">参考网址</span></a></li>
  </ol>
  <h2 data-lake-id="jzk8c" id="jzk8c"><span data-lake-id="u1e99c767" id="u1e99c767" style="color: var(--yq-text-primary)">Java中异常的处理方式有哪几种？一般如何选择。</span></h2>
  <p data-lake-id="u99d02623" id="u99d02623"><span data-lake-id="u4022f8f2" id="u4022f8f2">异常的处理方式有两种。1、自己处理。2、向上抛，交给调用者处理。</span></p>
  <p data-lake-id="ub9ad23db" id="ub9ad23db"><span data-lake-id="u12c59dee" id="u12c59dee">异常，千万不能捕获了之后什么也不做。或者只是使用e.printStacktrace。</span></p>
  <p data-lake-id="u1b799534" id="u1b799534"><span data-lake-id="u0be3471b" id="u0be3471b">具体的处理方式的选择其实原则比较简明：自己明确的知道如何处理的，就要处理掉。不知道如何处理的，就交给调用者处理<br></span><span data-lake-id="ud5a00049" id="ud5a00049"> </span></p>
 </body>
</html>